<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
				let flag=false
			function turn(){
				let img=document.querySelector(".con>img")//父子选择器,选择图像
				let h1=document.querySelector(".con>h1")
				//根据src的值判断开关灯
				//或是记录灯的状态
				if(flag){
					img.setAttribute("src","../src/off.png")
					h1.innerText="灯灭了"
					h1.setAttribute("style","color: black;")
					flag=false
				}//从开灯到关灯
				else{
					img.setAttribute("src","../src/on.png")
					h1.innerText="灯亮了"
					h1.setAttribute("style","color: red;")
					flag=true
				}
			}
		</script>
	</head>
	<body>
		<div class="con" style="text-align: center;" onclick="turn()">
			<img src="../src/off.png" width="200px">
			
			<h1>点击开灯</h1>
		</div>
	</body>
</html>
